/*******************************************************************
 * 外语翻译平台(translate) 
 *
 * 成都一亿信息技术公司 版权所有
 * 
 * Copyright (C) 2010 Transer Information Technology Co., Ltd.
 *
 * @Version : 1.0  2011-1-14 下午04:35:55
 *
 * JsonActionSupport.java
 *
 *******************************************************************/
package com.transer.web;

import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.transer.web.action.TranserActionSupport;

/**
 * class defination are there
 * 
 * @author Mark
 * 
 * @version 1.0 ywengineer@gmail.com
 * 
 */
public class JsonActionSupport extends TranserActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5613933892940874202L;

	protected void writeJsonMessage(boolean success, String message) throws Exception {
		Map<String, Object> msg = new HashMap<String, Object>();
		msg.put("success", success);
		msg.put("message", message);
		writeJson(JSONObject.fromObject(msg));
	}

	protected void writeJson(JSONObject json) throws Exception {
		HttpServletResponse response = ServletActionContext.getResponse();
		Writer writer = response.getWriter();

		response.setContentType("application/json;charset=utf-8");
		writer.write(json.toString());

		writer.flush();
		writer.close();
	}
}
